package net.xdclass.config;

import lombok.Data;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Data
public class RabbitMQERRConfig {
	private String shortLinkERRQueue = "short_link.error.queue";
	private String shortLinkERRExchange = "short_link.error.exchange";
	private String shortLinkErrorRoutingKey = "short_link.error.routing.key";

	@Autowired
	private RabbitTemplate rabbitTemplate;

	@Bean
	public Queue getShortLinkERRQueue(){
		return  new Queue(shortLinkERRQueue,true,false,false); 	}

	@Bean
	public Exchange getErrorExchange(){
		return  new TopicExchange(shortLinkERRExchange,true,false); }
    @Bean
	public Binding getBinding(){
		return  new Binding(shortLinkERRQueue,Binding.DestinationType.QUEUE,shortLinkERRExchange,shortLinkErrorRoutingKey,null);
	}

	@Bean
	public MessageRecoverer messageRecoverer(){
        return new RepublishMessageRecoverer(rabbitTemplate,shortLinkERRExchange,shortLinkErrorRoutingKey);
	}
}

